{{extend './extend.art'}}
{{block 'title'}}Blog - Content Manager{{/block}}
{{block 'body'}}
<body>
    {{include './header.art'}}
    <!-- 主体内容 -->
    <div class = "content">
        {{include './aside.art'}}
        <div class = "main">
            <!-- 分类标题 -->
            <div class = "title">
                <h4>文章</h4>
                <span>找到{{article.total}}篇文章</span>
                <a href = "/admin/article-edit" class = "btn btn-primary new">发布新文章</a>
            </div>
            <!-- /分类标题 -->
            <!-- 内容列表 -->
            <table class = "table table-striped table-bordered table-hover custom-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>发布时间</th>
                    <th>作者</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <!-- 使用了分页模块后 会将每一页的数据放到records这个数组中去 -->
                {{each article.records}}
                <tr>
                    <td>{{@$value._id}}</td>
                    <td>{{$value.title}}</td>
                    <!-- 处理时间 -->
                    <td>{{dateFormat($value.time,'yyyy-mm-dd')}}</td>
                    <td>{{$value.writer.name}}</td>
                    <td>
                        <a href = "/admin/article-edit?id={{@$value._id}}" class = "glyphicon glyphicon-edit"></a>
                        <i class = "glyphicon glyphicon-remove data-id" data-toggle = "modal"
                           data-id = "{{@$value._id}}"
                           data-target = ".confirm-modal"></i>
                    </td>
                </tr>
                {{/each}}
                </tbody>
            </table>
            <!-- /内容列表 -->
            <!-- 分页 -->
            <ul class = "pagination">
                <li style = "display:{{article.page<=1?'none':'inline'}}">
                    <a href = "/admin/article?page={{article.page-1}}">
                        <span>&laquo;</span>
                    </a>
                </li>
                {{each article.display}}
                <li><a href = "/admin/article?page={{$value}}">{{$value}}</a></li>
                {{/each}}
                <li style = "display:{{article.page>=article.pages?'none':'inline'}}">
                    <a href = "/admin/article?page={{article.page+1}}">
                        <span>&raquo;</span>
                    </a>
                </li>
            </ul>
            <!-- /分页 -->
        </div>
    </div>
    <!-- /主体内容 -->
    <!-- 删除确认弹出框 -->
    <div class = "modal fade confirm-modal">
        <div class = "modal-dialog modal-lg">
            <form class = "modal-content" method = "get" action = "/admin/article-delete">
                <div class = "modal-header">
                    <button type = "button" class = "close" data-dismiss = "modal"><span>&times;</span></button>
                    <h4 class = "modal-title">请确认</h4>
                </div>
                <div class = "modal-body">
                    <p>您确定要删除这篇文章吗?</p>
                    <input type = "hidden" name = "id">
                </div>
                <div class = "modal-footer">
                    <button type = "button" class = "btn btn-default" data-dismiss = "modal">取消</button>
                    <input type = "submit" class = "btn btn-primary" value = "确认删除">
                </div>
            </form>
        </div>
    </div>
    <!-- /删除确认弹出框 -->
    {{include './layout.art'}}

      <script>
      let data_id = $('i.data-id').attr('data-id')
      $('input[type=hidden]:eq(0)').val(data_id)

    </script>
</body>
{{/block}}